<?php

class ss_bucket_injector extends bucket_Container implements ss_core_injectorInterface{
	function __construct($factory = null, $scope = null) {
    	//ss_error::log($factory,'ss_bucket Factory');
		parent::__construct($factory, $scope);
		if(is_object($factory)) {
			$factory->setSingelton($this,'ss_bucket_injector');
			$factory->setInjector=$this;
		}
		$this->set($this);
		$this->registerImplementation('ss_core_injectorInterface','ss_bucket_injector');
  	}
}

class ss_bucket_factory{
	protected $settings;
	protected $injector;
	
	static protected $singeltons=array();
	
	public function __construct($settings){
		$this->settings=$settings;
		$this->setSingelton($settings,'site_core_config');
	}
	
	public function setInjector($obj){
		$this->injector=$obj;
	}
	
	public function new_ss_bucket_injector(){
		return $this->getSingelton('ss_bucket_injector');
	}
	
	public function new_site_templatefactory(){
		return new site_templatefactory($template_dir=realpath(SITE_ROOT_PATH . '/templates'),$template_dir . '_c',array('plugins',realpath(SS_ROOT_PATH . '/ss/smarty/plugins')));
	}
	
	public function new_Doctrine_Manager(){
		return Doctrine_Manager::getInstance();
	}
	
	public function new_site_core_config(){
		return $this->getSingelton('site_core_config');
	}
	
	public function new_ss_data_structure(){
		if(!$this->getSingelton('ss_data_structure')) $this->setSingelton(new ss_data_structure($this->settings));
		return $this->getSingelton('ss_data_structure');
	}
	/*
	public function new_ss_dao_trans(){
		if($result=$this->getSingelton($class)) return $result;
		return new ss_dao_trans(
			$this->settings->dao->default->type.':host='.$this->settings->dao->default->host.';dbname='.$this->settings->dao->default->database,
			$this->settings->dao->default->user,
			$this->settings->dao->default->pass,
			$this->settings->dao->default->conParam
			);
	}
	*/
	
	protected function getSingelton($class){
		$class=strtolower($class);
		if(array_key_exists($class,self::$singeltons)) return self::$singeltons[$class];
		return false;
	}
	
	public function setSingelton($obj,$class=null){
		if(empty($class))$class=get_class($obj);
		self::$singeltons[strtolower($class)]=$obj;
	}
	/*
	public function new_ss_dao_structure(){
		return new ss_dao_structure('')
	}
	*/
}
?>